﻿using System;

class HexadecimalToDecimal
{
    static void Main()
    {
        string hexNum = "FF";
        int deciNum = ConvertHexToDecimal(hexNum);

        Console.WriteLine("Hexadecimal: " + hexNum);
        Console.WriteLine("Decimal:     " + deciNum);
    }

    private static int ConvertHexToDecimal(string hexNum)
    {
        int deciNum = 0;
        int numBase = 16;
        int len = hexNum.Length - 1;

        for (int i = 0; i <= len; i++)
        {
            int digit = ConvertToHexSymbol(hexNum[i].ToString());
            deciNum += digit * (int)Math.Pow(numBase, len - i);
        }

        return deciNum;
    }

    private static int ConvertToHexSymbol(string hexDigit)
    {
        int deciDigit = 0;

        switch (hexDigit)
        {
            case "A":
                deciDigit = 10;
                break;
            case "B":
                deciDigit = 11;
                break;
            case "C":
                deciDigit = 12;
                break;
            case "D":
                deciDigit = 13;
                break;
            case "E":
                deciDigit = 14;
                break;
            case "F":
                deciDigit = 15;
                break;
            default:
                deciDigit = int.Parse(hexDigit);
                break;
        }

        return deciDigit;
    }
}
